//
//  gestureViewController.m
//  JFTRequest
//
//  Created by 竣付通 on 2017/11/14.
//  Copyright © 2017年 junHaoPay. All rights reserved.
//

#import "gestureViewController.h"
#import <LocalAuthentication/LocalAuthentication.h>
#import "HLMBProgressHUD.h"
@interface gestureViewController ()

@end

@implementation gestureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setLocalAuthentication];
}

-(void)setLocalAuthentication
{
    LAContext * context = [[LAContext alloc] init];
    context.localizedFallbackTitle = @"";
    NSError * error = nil;
    NSString * result = @"欢迎回来, 请将手指放置在指纹键上";
    
    //首先使用canEvaluatePolicy 判断设备支持状态
    if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error])
    {
        //支持指纹验证
        [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:result reply:^(BOOL success, NSError *error) {
            
            if (success)
            {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.navigationController popViewControllerAnimated:YES];
                });
            }
            else//验证失败
            {
                 dispatch_async(dispatch_get_main_queue(), ^{
                 [HLMBProgressHUD addMBProgressHUDinView:self.view hudMode:MBProgressHUDModeText hideDelay:2 hudDetailText:@"验证失败"];
                     });
            }
        }];
    }
    else
    {
         dispatch_async(dispatch_get_main_queue(), ^{
        //不支持指纹识别，LOG出错误详情
        [HLMBProgressHUD addMBProgressHUDinView:self.view hudMode:MBProgressHUDModeText hideDelay:2 hudDetailText:@"当前设备未开启指纹解锁,请开启系统指纹或关闭应用指纹解锁"];
             });
    }
}

@end
